package com.google.code.p.narcissus.ui.components.utils;

import java.io.File;
import java.io.FileFilter;
import java.util.Comparator;

public  class FileHandlingUtility {
	
	
	public static FileFilter createExtensionFilter(final String extensionWithoutDot){
		return new FileFilter() {
			@Override
			public boolean accept(File file) {
				return file.isFile() && file.getName().toLowerCase().endsWith("." + extensionWithoutDot);
			}
		};
	}
	
	public static FileFilter createDirectoryFilter(){
		return new FileFilter() {
			@Override
			public boolean accept(File pathname) {
				return pathname.isDirectory();
			}
		};
	}
	
	public static FileFilter regexFileFilter(final String regex){
		return new FileFilter() {
			@Override
			public boolean accept(File pathname) {
				return pathname.getName().matches(regex);
			}
		};
	}
	
	public static Comparator<File> createFileNameComparator(){
		return new Comparator<File>() {

			@Override
			public int compare(File o1, File o2) {
				return o1.getName().compareTo(o2.getName());
			}
		};
	}

}
